/**
 * 测试sigset结构体，以及一些信号集操作函数；
 * @author: sundx
 * @date: 2020-05-23 23:42:05
 * @Last Modified by: sundx
 * @Last Modified time: 2020-05-24 01:00:07
 */
#include <iostream>
#include <signal.h>
#include <sys/wait.h>
#include <unistd.h>
void printSigSet(sigset_t);
int main() {
  sigset_t mySet, oldSet, krlSet;
  sigemptyset(&mySet);
  sigaddset(&mySet, SIGINT);
  // sigaddset(&mySet,SIGINT);
  sigprocmask(SIG_BLOCK, &mySet, &oldSet); // 设置阻塞；
  while (1) {
    sleep(1);
    sigpending(&krlSet); // 每隔1s查看一次内核未决信号集并打印
    printSigSet(krlSet);
  }
  sigprocmask(SIG_UNBLOCK, &mySet, &oldSet);
}
void printSigSet(sigset_t set) {
  int i;
  for (i = 1; i < 32; ++i) {
    if (sigismember(&set, i)) {
      std::cout << 1;
    } else {
      std::cout << 0;
    }
  }
  std::cout << std::endl;
}
